<template>
  <div class="form-container">
    <el-form ref="addForm" :model="addForm" label-width="200px">
      <el-form-item label="今日已完成事项">
        <el-input v-model="addForm.success" type="textarea"></el-input>
      </el-form-item>
      <el-form-item label="今日未完成事项">
        <el-input v-model="addForm.incomplete" type="textarea"></el-input>
      </el-form-item>
      <el-form-item label="是否需要同事协助">
        <el-select v-model="addForm.help" placeholder="请选择是否需要帮助">
          <el-option label="是" value="0"></el-option>
          <el-option label="否" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="每天是否在成长">
        <el-select v-model="addForm.development" placeholder="请选择是否成长">
          <el-option label="是" value="0"></el-option>
          <el-option label="否" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="客户情况分析">
        <el-input v-model="addForm.analysis" type="textarea"></el-input>
      </el-form-item>
      <el-form-item label="工作总结">
        <el-input v-model="addForm.summarize" type="textarea"></el-input>
      </el-form-item>
      <el-form-item label="明天工作计划">
        <el-input v-model="addForm.plan" type="textarea"></el-input>
      </el-form-item>
      <el-form-item label="提交时间" v-show="false">
        <el-input v-model="addForm.submissionDate" type="textarea"></el-input>
      </el-form-item>
      <el-form-item>
<!--      <el-button @click.native="addFormVisible = false">取消创建</el-button>-->
      <el-button v-perm="'employeeLog/AddLog'" type="primary" @click.native="addSubmit" :loading="addLoading">提交日志</el-button>
        </el-form-item>
    </el-form>
  </div>
</template>
<script>
import util from '../../common/js/util'
export default {
  data() {
    return {
      addFormVisible: false,//新增界面是否显示
      addLoading: false,
      addFormRules: {},
      //新增界面数据
      addForm: {
        id:null,
        success:'',
        incomplete:'',
        help:'',//0: 是, 1: 否
        development:'',// 0: 是, 1: 否
        analysis:'',
        summarize:'',
        plan:'',
        submissionDate:''
      },
       //业务员           // //员工所属部门
         salesMan:[],        // departments: [],
    }
  },
  methods: {
    //获取业务员
    getSalesman() {
      this.$http.get("/customSalesman").then(res=>{
        this.salesMan = res.data;
      })
    },
    //6.选项改变时触发
    selsChange: function (sels) {
      this.sels = sels;
    },
    //11.新增
    addSubmit: function () {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交日志吗？', '提示', {}).then(() => {
            this.addLoading = true;
            // 在提交前获取当前时间
            const currentDate = new Date().toISOString(); // 或者使用您需要的日期格式
            this.addForm.submissionDate = currentDate;
            // 转换为数字类型（0 或 1）
            this.addForm.help = this.addForm.help === '0' ? '0' : '1';
            this.addForm.development = this.addForm.development === '0' ? '0' : '1';

            let para = Object.assign({}, this.addForm);
            para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd');
            this.$http.put("/customEmployeelog", para).then(res => {

              if (res.data.success) {
                this.$message({
                  message: '日志添加成功',
                  type: 'success'
                });
                this.$refs['addForm'].resetFields();
                this.$router.push('/employeelog');
              } else {
                this.$message.warning("系统繁忙，请稍后重试!!!");
              }
              this.addLoading = false;
              this.addFormVisible = false;
              this.getcustomerLists();
            });
          });
        }
      });
    },
  },
  mounted() {
    this.getcustomerLists();

  }
}

</script>
<style>
.form-container {
  margin-top: 50px;
  margin-left: 10px;
  width: 800px;
  height: 800px;
}
</style>
<style scoped>

</style>